<?php
/**
 * Created by PhpStorm.
 * User: MyPC
 * Date: 2016/7/20
 * Time: 13:29
 */

namespace Admin\Model;
use \Think\Model;

class UsersModel extends Model{
    //添加自动验证规则
    protected $_validate = array(
        array('username', 'require', '账号必须！', 1),
        array('username', '', '账号已经存在', 0, 'unique', self::MODEL_INSERT),
        array('username',array('administrator','admin'),'用户名不能是administrator或admin',1,'notin'),
        array('pass', 'require', '密码必须！', 1),
        array('pass2','pass','两次密码不一致',0,'confirm',1),//插入验证
        array('realname', 'require', '真实姓名必须'),
        array('email', 'require', '邮箱必须！', 1),
    );
    //添加自动填充规则
    protected $_auto = array(
        //为think_users表的createtime字段生成当前的日期
        array('createtime',"date('Y-m-d')",self::MODEL_INSERT, 'function'),
        //为think_users表的pass字段进行md5加密
        array('pass','md5', self::MODEL_INSERT, 'function'),
    );
}